
import requests
import csv

def get_data():
    url = 'https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1708743664770&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword=python&pageIndex=1&pageSize=10&language=zh-cn&area=cn'
    res = requests.get(url)
    items = res.json()
    datas = list()
    for data in items.get('Data')['Posts']:
        RecruitPostName = data.get('RecruitPostName')
        LocationName = data.get('LocationName')
        Responsibility = data.get('Responsibility')
        datas.append([RecruitPostName, LocationName, Responsibility])

    with open('tx.csv', 'w', encoding='utf-8-sig', newline='') as f:
        writer = csv.writer(f);
        # 写一个头部
        writer.writerow(['岗位', '地区', '简介'])
        # 开始写数据
        writer.writerows(datas)
        print('数据写入完毕！')

if __name__ == '__main__':
    get_data()